<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-tourist__istourist">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.name"
            placeholder="姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.card"
            placeholder="身份证号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.phone"
            placeholder="手机号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="enterDateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            clearable
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <SelectComponent
            dictType="tourist_type"
            v-model="dataForm.type"
            placeholder="门票类型"
          >
          </SelectComponent>
        </el-form-item>
        <el-form-item>
          <SelectComponent
            dictType="tourist_order_type"
            v-model="dataForm.orderType"
            placeholder="订单类型"
          >
          </SelectComponent>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.province"
            placeholder="省"
            clearable
            @change="(val) => regionChange(val, 'province')"
          >
            <el-option
              v-for="item in provinceOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.city"
            placeholder="市"
            clearable
            @change="(val) => regionChange(val, 'city')"
          >
            <el-option
              v-for="item in cityOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.area"
            placeholder="区"
            clearable
            @change="(val) => regionChange(val, 'area')"
          >
            <el-option
              v-for="item in areaOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>

        <el-form-item>
          <el-button
            v-if="$hasPermission('sys:istourist:save')"
            type="primary"
            @click="addOrUpdateHandle()"
            >{{ $t("add") }}</el-button
          >
        </el-form-item>
        <el-form-item v-if="$hasPermission('sys:istourist:export')">
          <el-button type="primary" @click="exportHandle()">{{
            $t("export")
          }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('sys:istourist:delete')"
            type="danger"
            @click="deleteHandle()"
            >{{ $t("deleteBatch") }}</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="card"
          label="身份证号"
          header-align="center"
          :show-overflow-tooltip="true"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="phone"
          label="手机号"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="enterDate"
          label="入园时间"
          :show-overflow-tooltip="true"
          min-width="120"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="provinceName"
          label="位置信息"
          header-align="center"
          align="center"
          min-width="150px"
        >
          <template slot-scope="scope">
            {{ scope.row.provinceName }}/ {{ scope.row.cityName }}/
            {{ scope.row.areaName }}/ {{ dataForm.street }}/
            {{ dataForm.areaDetail }}
          </template>
        </el-table-column>
        <el-table-column
          prop="typeName"
          label="门票类型"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="orderTypeName"
          label="订单类型"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button
              v-if="$hasPermission('sys:istourist:update')"
              type="text"
              size="small"
              @click="addOrUpdateHandle(scope.row.id)"
              >{{ $t("update") }}</el-button
            >
            <!-- <el-button type="text" size="small" @click="viewHandle(scope.row)"
              >查看</el-button
            > -->
            <el-button
              v-if="$hasPermission('sys:istourist:delete')"
              type="text"
              size="small"
              @click="deleteHandle(scope.row.id)"
              >{{ $t("delete") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
        :disabled="disabled"
        @changeDisabled="disabled = false"
      ></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./istourist-add-or-update";
import mixinRegionModule from "@/mixins/region-module";
export default {
  mixins: [mixinViewModule, mixinRegionModule],
  data() {
    return {
      disabled: false,

      enterDateRange: [],
      mixinViewModuleOptions: {
        getDataListURL: "/sys/istourist/page",
        getDataListIsPage: true,
        exportURL: "/sys/istourist/export",
        deleteURL: "/sys/istourist",
        deleteIsBatch: true,
      },
      dataForm: {
        name: "",
        card: "",
        phone: "",
        enterDateStart: "",
        enterDateEnd: "",
        province: "",
        city: "",
        area: "",
      },
    };
  },
  created() {
    this.provincAreaDetailInfoList();
    if (this.dataForm.city) {
      this.cityAreaDetailInfoList(this.dataForm.province);
    }
    if (this.dataForm.area) {
      this.countyAreaDetailInfoList(this.dataForm.city);
    }
  },
  watch: {
    enterDateRange: {
      immediate: true,
      deep: true,
      handler(newVal) {
        this.splitTimeRange();
      },
    },
  },
  components: {
    AddOrUpdate,
  },
  methods: {
    viewHandle(row) {
      this.addOrUpdateVisible = true;
      this.disabled = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.visible = true;
        this.$refs.addOrUpdate.dataForm = row;
      });
    },
    splitTimeRange() {
      if (this.enterDateRange) {
        // 取值
        this.dataForm.enterDateStart = this.enterDateRange[0];
        this.dataForm.enterDateEnd = this.enterDateRange[1];
      } else {
        this.dataForm.enterDateStart = "";
        this.dataForm.enterDateEnd = "";
      }
    },
  },
};
</script>
